package com.xiashitech.apiservice.util;

import java.io.*;

import org.apache.tika.Tika;
import org.springframework.web.multipart.MultipartFile;

import static com.xiashitech.apiservice.Constants.FileType.CONTENT_TYPE_STREAM;

public class FileUtil {

    public static String getContentType(MultipartFile file) throws IOException {
        String contentType = file.getContentType();
        if (contentType == null || contentType.equals(CONTENT_TYPE_STREAM)) {
            Tika tika = new Tika();
            contentType = tika.detect(file.getInputStream());
        }
        return contentType;
    }

}
